package com.genesis.yunnanji.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.genesis.yunnanji.R;
import com.genesis.yunnanji.activity.StoreWeb;
import com.genesis.yunnanji.bean.GoodsNewsBean;
import com.genesis.yunnanji.config.GenesisApiConfig;
import com.genesis.yunnanji.utils.DateUtils;

import java.util.List;

/**
 * 创建日期：2018/10/19 001915:45
 * 作者：Kite
 * 描述：
 */
public class GoodsNewsAdapter extends BaseQuickAdapter<GoodsNewsBean.ResultBean.ListBean, BaseViewHolder> {

    private Context mContext;

    public GoodsNewsAdapter(Context mContext, int layoutResId, List<GoodsNewsBean.ResultBean.ListBean> mNewsDate) {
        super(layoutResId, mNewsDate);
        this.mContext = mContext;
    }

//    @NonNull
//    @Override
//    public NewsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
//        return new GoodsNewsAdapter.NewsViewHolder(LayoutInflater.from(mContext).inflate(R.layout.layout_newstext, viewGroup, false));
//    }

    @Override
    protected void convert(BaseViewHolder newsViewHolder, final GoodsNewsBean.ResultBean.ListBean item) {
        Glide.with(mContext).load(GenesisApiConfig.PIC_HOST + item.getCover_img() + "?x-oss-process=image/resize,m_fill,w_260,h_150").into((ImageView) newsViewHolder.getView(R.id.iv_newstext_icon));
        newsViewHolder.setText(R.id.tv_newstext_title, item.getTitle());
        newsViewHolder.setText(R.id.tv_newstext_date, DateUtils.getTimeOfYMD(item.getAdd_time()));
        newsViewHolder.setVisible(R.id.tv_newstext_topnews, false);
        newsViewHolder.getView(R.id.rl_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("lk", "onClick: " + item.getId());
                Intent intent = new Intent(mContext, StoreWeb.class);
                intent.putExtra("url",item.getTaget_link());
                mContext.startActivity(intent);
            }
        });

    }

//    @Override
//    public void onBindViewHolder(@NonNull NewsViewHolder newsViewHolder, int i) {
//        Glide.with(mContext).load(GenesisApiConfig.PIC_HOST + mNewsDate.get(i).getCover_img() + "?x-oss-process=image/resize,m_fill,w_260,h_150").into(newsViewHolder.imageView);
//        newsViewHolder.title.setText(mNewsDate.get(i).getTitle());
//        newsViewHolder.dataTime.setText(DateUtils.getTimeOfYMD(mNewsDate.get(i).getAdd_time()));
//        newsViewHolder.topNews.setVisibility(View.GONE);
//    }

    public static class NewsViewHolder extends RecyclerView.ViewHolder {

        ImageView imageView;
        TextView title;
        TextView dataTime;
        TextView topNews;

        public NewsViewHolder(View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.iv_newstext_icon);
            title = itemView.findViewById(R.id.tv_newstext_title);
            dataTime = itemView.findViewById(R.id.tv_newstext_date);
            topNews = itemView.findViewById(R.id.tv_newstext_topnews);
        }
    }

}
